#ifndef TEMPLIB_H_
#define	TEMPLIB_H_

#include "stdint.h"
#include "dataproc.h"
#include "correct.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define TEMP_ERR_LIMITE_H_MASK          0x01
#define TEMP_ERR_LIMITE_L_MASK          0x10
#define TEMP_ERR_TABLE_H_MASK           0x02
#define TEMP_ERR_TABLE_L_MASK           0x20
    
#define TEMP_TAB_DATA_END               INT32_MAX

    typedef struct
    {
        int32_t Division;
        int32_t Temp;             
        
    } TEMP_TABLE_Type;
    
    typedef struct
    {
        int32_t MarkADL;
        int32_t MarkADH;
    } TEMP_AD_MARK_Type;
    
    typedef struct
    {
        int32_t DivisionL;
        int32_t DivisionH;
    } TEMP_DIVISION_Type;	
	
    typedef struct
    {
        int32_t pb;
        int32_t pk;
    } TEMP_CORRECT_Type;
    
    typedef struct
    {
        int32_t LimiteH;
        int32_t LimiteL;
    } TEMP_LIMITE_Type;
    
    typedef enum
    {
        TEMP_CORRECT_MODE_PBPK = 0,
        TEMP_CORRECT_MODE_FLOAT_LIST = 1,
        TEMP_CORRECT_MODE_INT_LIST = 2,
        TEMP_REMAP_MODE_FLOAT_LIST = 3,
        TEMP_REMAP_MODE_INT_LIST = 4,
    } temp_correct_mode_type;
    
	typedef struct
	{
		uint8_t Err;
        uint8_t bCFEn;
		int32_t AdcVal;
        float TempOrg; 
		float Temp;
		float TempReal;
		float TempDis;
        float Flt;
		const TEMP_TABLE_Type *TempTab;
        TEMP_DIVISION_Type Division;
		TEMP_AD_MARK_Type Mark;
		TEMP_CORRECT_Type Correct;
		TEMP_LIMITE_Type Limite;
        
        float coef; 

        int16_t iTempCtr;
        int16_t iTempDisp;
        int16_t iTempOrg;
        
        uint8_t correct_point_len;
        temp_correct_mode_type correct_mode;
        void *correct_list;
        
	} TEMP_OBJ_Type;
    
    void TempCal(TEMP_OBJ_Type* TempObj);
    float  TempGet(TEMP_OBJ_Type* TempObj);
	int16_t TempIntGet(TEMP_OBJ_Type* TempObj);
	int16_t  DispTempGet(TEMP_OBJ_Type* TempObj);
    void TempADSet(TEMP_OBJ_Type* TempObj ,int16_t AD_Val);
    uint8_t TempErrGet(TEMP_OBJ_Type* TempObj);
	float Pt100_ResToTemp(float m_Res);
    float Pt100_TempToRes(float m_Temp);

    void temp_cal_imap(TEMP_OBJ_Type *TempObj);
        
    void temp_cal_pbpk(TEMP_OBJ_Type *TempObj);
    
#ifdef	__cplusplus
}
#endif

#endif	

